package com.zmn.oms.admin;

import com.github.ltsopensource.spring.boot.annotation.EnableJobClient;
import com.zmn.brs.starter.annotation.EnableBusinessRisk;
import com.zmn.framework.web.config.FastJsonHttpMessageConverterConfiguration;
import com.zmn.manager.common.database.config.OneMasterMultiSlaveDataSourceConfiguration;
import com.zmn.manager.mq.annotation.EnableMQSend;
import com.zmn.manager.sharding.annotation.EnableMyIdAutoAlloter;
import com.zmn.mcc.permit.client.annotation.EnableControllerPermitData;
import com.zmn.oms.admin.thymeleaf.ZmnDialect;
import com.zmn.oms.manager.utils.SpringBeanFactoryUtil;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchDataAutoConfiguration;
import org.springframework.boot.autoconfigure.elasticsearch.rest.RestClientAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Import;
import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;
import org.springframework.web.multipart.MultipartResolver;
import org.springframework.web.multipart.commons.CommonsMultipartResolver;

@SpringBootApplication(exclude = { RabbitAutoConfiguration.class, DataSourceAutoConfiguration.class,
        ElasticsearchDataAutoConfiguration.class, RestClientAutoConfiguration.class
})
@ComponentScan(basePackages = "com.zmn.oms")
@Import({OneMasterMultiSlaveDataSourceConfiguration.class, FastJsonHttpMessageConverterConfiguration.class, SpringBeanFactoryUtil.class})
//@EnableElasticsearchRepositories(basePackageClasses = {
//        EsOrderWorkService.class,
//        EsOrderPartService.class,
//        EsOrderPayService.class
//})
@EnableBusinessRisk(tenant = "com.zmn.brs")
@EnableJobClient
@EnableMyIdAutoAlloter
@EnableTransactionManagement
@EnableAsync
@EnableMQSend
@EnableControllerPermitData
public class AdminApplication {

    public static void main(String[] args) {
        System.setProperty("es.set.netty.runtime.available.processors", "false");
        SpringApplication.run(AdminApplication.class, args);
    }

    /**
     * thymeleaf
     *
     * @return
     */
    @Bean
    @ConditionalOnMissingBean
    public ZmnDialect zmnDialect() {
        return new ZmnDialect("zmn-utils");
    }

    @SuppressWarnings("Duplicates")
    @Bean(name = "multipartResolver")
    public MultipartResolver multipartResolver() {
        CommonsMultipartResolver resolver = new CommonsMultipartResolver();
        resolver.setResolveLazily(true);
        resolver.setMaxInMemorySize(40960);
        // 上传文件大小 10M 10*1024*1024
        resolver.setMaxUploadSize(10 * 1024 * 1024);
        return resolver;
    }

}